const mongoose = require('mongoose')
const nodemailer = require('nodemailer')

const Mongoose = {
  URI:
    'mongodb+srv://new-user_1:liang19921222@master-k0edp.mongodb.net/miaomiao?retryWrites=true&w=majority',
  connect() {
    mongoose.connect(
      this.URI,
      {
        useNewUrlParser: true,
        useFindAndModify: false
      },
      err => {
        if (err) {
          console.log('数据库连接失败')
          return
        }
        console.log('数据库连接成功')
      }
    )
  }
}

const Email = {
  config: {
    host: 'smtp.qq.com',
    port: 587,
    secure: false, // true for 465, false for other ports
    auth: {
      user: '935840006@qq.com', // generated ethereal user
      pass: 'lelptkgtvfltbcab' // generated ethereal password
    }
  },
  get transporter() {
    return nodemailer.createTransport(this.config)
  },
  get verify() {
    return Math.random()
      .toString()
      .substring(2, 6)
  },
  get time() {
    return Date.now()
  }
}

const Head = {
  baseUrl: 'http://localhost:3000/uploads/'
}

module.exports = {
  Mongoose,
  Email,
  Head
}
